package com.it135.citytraffic.controller;


import com.it135.citytraffic.pojo.dto.UserRoadReasonDTO;
import com.it135.citytraffic.pojo.result.Result;
import com.it135.citytraffic.pojo.vo.ReasonVO;
import com.it135.citytraffic.pojo.vo.UserRoadReasonVO;
import com.it135.citytraffic.service.IUserRoadReasonService;
import com.it135.citytraffic.utils.ReasonsUtils;
import lombok.Data;
import lombok.extern.slf4j.Slf4j;
import org.springframework.web.bind.annotation.*;

import java.util.ArrayList;
import java.util.List;


@RestController
@RequestMapping("/api/userFeedBack")
@Data
@Slf4j
public class UserRoadReasonController {

    private  final IUserRoadReasonService userRoadReasonService;
    @CrossOrigin
    @GetMapping("/reason")
    public Result<List<ReasonVO>> getRoadReason(){
        ArrayList<ReasonVO> reasonVOS = new ArrayList<>();
        for (int i = 1;true ; i++) {
            String reason = ReasonsUtils.getReason(i);
            reasonVOS.add(new ReasonVO(i,reason));
            if(reason.equals("其他"))break;
        }
        return  Result.success(reasonVOS);
    }
    @CrossOrigin
    @PostMapping()
    public Result submitReason(@RequestBody UserRoadReasonDTO userRoadReasonDTO ){
        log.info("用户提交的拥堵原因：{}",userRoadReasonDTO);
        userRoadReasonService.submitReason(userRoadReasonDTO);
        return  Result.success();
    }


    @CrossOrigin
    @GetMapping("/getCount")
    public Result<UserRoadReasonVO> getCount() {
        UserRoadReasonVO userRoadReasonVO = userRoadReasonService.getCount();
        return Result.success(userRoadReasonVO);
    }
}
